<template>
    <el-form ref="form" label-width="80px" style="padding:20px">
        <el-form-item label="权限等级">
            <el-input v-model="gradeid" placeholder="请输入权限等级(要求输入大于0的数字)"></el-input>
        </el-form-item>
        <el-form-item label="等级描述">
            <el-input type="textarea" placeholder="请输入权限等级描述" v-model="remarks"></el-input>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submit">保存</el-button>
            <el-button @click="close">取消</el-button>
        </el-form-item>
    </el-form>
</template>
<script>
import C from '@/common/common.js'

export default {
  name: 'addRule',
  data () {
    return {
      id: 0,
      gradeid: '',
      remarks: ''
    }
  },
  methods: {
    async submit () {
      if (!/^[1-9]\d*$/.test(this.gradeid)) {
        C.error('请填写要添加的权限等级')
        return false
      }
      if (this.remarks == '') {
        C.error('请填写该权限描述')
        return false
      }
      var data = {
        id: this.id,
        gradeid: this.gradeid,
        remarks: this.remarks
      }

      let res = await C.ajax('/shop/rule/addotherpermission', data, 'post')
      if (res) {
        C.closeBrowserWindow(res)
      }
    },
    close () {
      C.closeBrowserWindow()
    }
  },
  mounted: function () {
    let row = C.getDatas()
    if (row.id) {
      this.id = row.id
      this.gradeid = row.gradeid
      this.remarks = row.remarks
    }
  }
}
</script>